package com.handmark.pulltorefresh.library.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.R;
import com.handmark.pulltorefresh.library.internal.LoadingLayout;

/**
 * 任继波
 * Created by Administrator on 2017/2/22.
 */

public class MyApplicationOne extends LoadingLayout{
    private AnimationDrawable animationDrawable;

    public MyApplicationOne(Context context, PullToRefreshBase.Mode mode,
                            PullToRefreshBase.Orientation scrollDirection, TypedArray attrs) {
        super(context, mode, scrollDirection, attrs);
        // 初始化
        mHeaderImage.setImageResource(R.drawable.qqq);
        mHeaderImage.setVisibility(View.GONE);
        animationDrawable = (AnimationDrawable) mHeaderImage.getDrawable();
    }
    // 默认图片
    @Override
    protected int getDefaultDrawableResId() {

//        Log.d("Renjibo","getDefaultDrawableResId");
        return R.drawable.loading_double_1;
    }

    @Override
    protected void onLoadingDrawableSet(Drawable imageDrawable) {
        // NO-OP
        pull_to_refresh_myView.setVisibility(View.GONE);
//        Log.d("Renjibo","onLoadingDrawableSet");
    }

    /**
     * 修改位置
     * @param scaleOfLayout
     */
    @Override
    protected void onPullImpl(float scaleOfLayout) {
        // NO-OP
        if(scaleOfLayout<=1){
                pull_to_refresh_myView.setXY((float) (scaleOfLayout),(float) (scaleOfLayout));
                pull_to_refresh_myView.invalidate();

//                pull_to_refresh_myView.setXY(a,a);

        }else{
            pull_to_refresh_myView.setXY(1,1);
            pull_to_refresh_myView.invalidate();
        }

//        Log.d("Renjibo",""+scaleOfLayout);

    }
    // 下拉以刷新
    @Override
    protected void pullToRefreshImpl() {
        // NO-OP
        pull_to_refresh_myView.setVisibility(View.VISIBLE);
        mHeaderImage.setVisibility(View.GONE);
//        Log.d("Renjibo","pullToRefreshImpl");
    }
    // 正在刷新时回调
    @Override
    protected void refreshingImpl() {
        // 播放帧动画

        //mHeaderImage.setVisibility(View.VISIBLE);
        animationDrawable.start();
//        Log.d("Renjibo","refreshingImpl");
    }
    // 释放以刷新
    @Override
    protected void releaseToRefreshImpl() {
        // NO-OP
        pull_to_refresh_myView.setVisibility(View.VISIBLE);
//        mHeaderImage.setVisibility(View.GONE);
//        Log.d("Renjibo","releaseToRefreshImpl");
    }
    // 重新设置
    @Override
    protected void resetImpl() {
        pull_to_refresh_myView.setXY(-20,-20);
        pull_to_refresh_myView.invalidate();
//        pull_to_refresh_myView.setVisibility(View.GONE);
        mHeaderImage.clearAnimation();
//        Log.d("Renjibo","resetImpl");
    }

}
